package xianchenglock1;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;

public class semm {
    private static  final  int MAX_A = 5;

    public static void main(String[] args) {

//        List<String> e = new CopyOnWriteArrayList<>();
        Semaphore semaphore = new Semaphore(MAX_A);
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                try {
                    semaphore.acquire();
                    System.err.println(Thread.currentThread().getName()+"获取到所");
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                semaphore.release();
                System.err.println(Thread.currentThread().getName()+"释放了锁");
            }).start();
        }
    }
}
